<?

  class CFD_Cart

  {

    /**

     * costArray - cost definitions

     * 

     * @var array

     * @access private

    **/

    private $costArray = array();

    private $cartSession = null;

    private function __construct(Zend_Session_Namespace $cartSession)
	{
	  $this->cartSession = $cartSession;
/*
	  $this->costArray = array('voucher' => '0.0001',
	     'bulkCredit' => array(
		  array('count' => 10, 'cost' => '0.001', 'description' => '10 vouchers for 0.001 BTC'),
		  array('count' => 20, 'cost' => '0.002', 'description' => '10 vouchers for 0.002 BTC'),
		  array('count' => 30, 'cost' => '0.003', 'description' => '20 vouchers for 0.002 BTC')
	  ));*/
	}

	private static $cartObj = null;

	public static function getCartObj()
	{
	  if (!self::$cartObj)
	    self::$cartObj = new CFD_Cart(new Zend_Session_Namespace('cart'));

	  return self::$cartObj;
	}

	public function addToCart($valuationId)
	{
	  $this->cartSession->cart[$valuationId] = $valuationId;
	}

	public function delFromCart($valuationId)
	{
	  unset($this->cartSession->cart[$valuationId]);
	}

	public function getItems()
	{
		$valuationsTable = new Application_Model_Vouchers();
		$select = $valuationsTable->select();

		$select->orWhere('1 = 2');

		foreach ((array)$this->cartSession->cart as $vID)
			$select->orWhere('id = ?', $vID);

		$results = $valuationsTable->fetchAll($select);
		return $results;
	}

	public function calculateCost()
	{
		$totalCost = 0;
		foreach($this->getItems() as $item) {
			$totalCost = $totalCost + floatval( $item->price );
		}
	  return $totalCost; //count($this->getItems())*$this->costArray['voucher'];
	}

/*	public function getCostArray()
	{
	  return $this->costArray;
	} */
  }

